package builder.AccountFormBuilderPackage;

import handler.assetFormHandlers.AFTextFieldKeyListener;

import javax.swing.BoxLayout;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import builder.FormBuilder;
import builder.FormBuilderDecorator;
import checker.ValidLengthAndCharChecker;
import form.FormTextField;
import form.AccountForm.AccountForm;

public class OtherInfoDecorator extends FormBuilderDecorator {

	public OtherInfoDecorator(FormBuilder decoratee) {
		super(decoratee);
	}

	public void setFormSettings() {
		// TODO Auto-generated method stub
		super.setFormSettings();

	}

	public void buildComponents() {
		super.buildComponents();

		AccountForm accountForm = (AccountForm) decoratee.getForm();
		accountForm.setLayout(new BoxLayout(decoratee.getForm(), BoxLayout.Y_AXIS));
		buildRetypePasswordTF(accountForm);
		buildFirstnameTF(accountForm);
		buildLastnameTF(accountForm);
		
	}

	public void buildFirstnameTF(AccountForm accountForm){
		JTextField FName = new JTextField();
		FName.setColumns(10);
		FormTextField FNameTF = new FormTextField("First Name:", FName, new ValidLengthAndCharChecker(ValidLengthAndCharChecker.ALPHANUMERIC,20));
		accountForm.getAccountInfoForm().setFName(FNameTF);
		FName.addKeyListener(new AFTextFieldKeyListener(FNameTF));
		accountForm.add(FNameTF);
	}

	public void buildLastnameTF(AccountForm accountForm) {
		JTextField LName = new JTextField();
		LName.setColumns(10);
		FormTextField LNameTF = new FormTextField("Last Name:", LName,
				new ValidLengthAndCharChecker(
						ValidLengthAndCharChecker.ALPHANUMERIC,20));
		accountForm.getAccountInfoForm().setLName(LNameTF);
		LName.addKeyListener(new AFTextFieldKeyListener(LNameTF));
		accountForm.add(LNameTF);
	}

	public void buildRetypePasswordTF(AccountForm accountForm) {
		JPasswordField retypepassword = new JPasswordField();
		retypepassword.setColumns(10);
		FormTextField retypePasswordTF = new FormTextField(
				"Retype Password:", retypepassword,
				new ValidLengthAndCharChecker(
						ValidLengthAndCharChecker.ALPHANUMERIC,20));
		accountForm.getAccountInfoForm().setRetypePassword(retypePasswordTF);
		retypepassword.addKeyListener(new AFTextFieldKeyListener(
				retypePasswordTF));
		accountForm.add(retypePasswordTF);
	}

}
